package com.example.luohao.myrecyclerviewdemo;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.zhxu.recyclerview.adapter.CommonAdapter;
import com.zhxu.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目名称：MyRecyclerViewDemo
 * 类描述：利用RecyclerView封装框架完成最基础的单一条目展示
 * 创建人：luohao
 * 创建时间：2018/1/31 23:28
 * 修改人：luohao
 * 修改时间：2018/1/31 23:28
 * 修改备注：
 */

public class Activity1 extends AppCompatActivity {

    private RecyclerView mRV1;
    private List<String> stringList = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.actvity_recycler);
        mRV1 = (RecyclerView) this.findViewById(R.id.mRV1);
        for (int i = 0; i < 108; i++) {
            String str = "条目" + i;
            stringList.add(str);
        }
        mRV1.setLayoutManager(new LinearLayoutManager(this));
        MyCommonAdapter myCommonAdapter = new MyCommonAdapter(this);
        myCommonAdapter.addDataAll(stringList);
        mRV1.setAdapter(myCommonAdapter);
    }

    class MyCommonAdapter extends CommonAdapter<String> {

        public MyCommonAdapter(Context context) {
            super(context, R.layout.item_common);
        }

        @Override
        protected void convert(ViewHolder holder, String s, int position) {
            holder.setText(R.id.mTV_common, stringList.get(position));
        }
    }
}
